<template>
	<view class="container" :style="[containHeight]">
		<view class="people-container">
			<view>
				<u-alert :title="titleStudy" type="warning" :closable="isClosable" :description="description"
					@click="openAlert()"></u-alert><!-- v-if="authDegree==2||authDegree==3" -->
			</view>

			<view class="people-content">
				<view class="today" v-if="Object.keys(employeeData).length==0">个人基本信息 </view>
				<u-empty v-if="Object.keys(employeeData).length==0" mode="data" icon="../../static/dataEmpty.png">
				</u-empty>
				<u-collapse v-else :value="['basicInfo']">
					<u-collapse-item name="basicInfo" class="collapse-item" :title="employeeData.username">
						<view class="people-info-content">
							<view class="layout-start">
								<view class="people-info-item">
									<u--image :src="employeeData.imgSrc" width="78px" height="110px">
										<view slot="error" style="font-size: 24rpx;">加载失败</view>
									</u--image>
									<!-- <u--image :showLoading="true" :src="employeeData.imgSrc" width="78px" height="110px"></u--image> -->
									<!-- <img :src="employeeData.imgSrc" class="inch-photo"> -->
								</view>
								<view class="basicInfo">
									<view class="people-info-item">
										<view><text class="bold"> 工号： </text>{{employeeData.employeeId}}</view>
									</view>
									<view class="people-info-item">
										<view><text class="bold"> 卡号： </text>{{employeeData.cardNo}}</view>
									</view>
									<view class="people-info-item">
										<view><text class="bold"> 工种： </text>{{employeeData.jobType}}</view>
									</view>
									<view class="people-info-item">
										<view><text class="bold">部门：</text>{{employeeData.deptName}}</view>
									</view>
								</view>
							</view>
							<view class="people-info-item bold">
								<text class="bold"> 分数区段:</text>
								<text v-if="employeeData.level == '低风险'" class="green">
									放心人员<!-- 安全意识较强（90-100） -->
								</text>
								<text v-if="employeeData.level == '中风险'" class="yellow">
									预警人员<!-- 安全意识适中（75-90） -->
								</text>
								<text v-if="employeeData.level == '高风险'" class="red">
									薄弱人员<!-- 安全意识一般（50-75） -->
								</text>
							</view>
							<view class="people-info-item"><!-- v-if="!loadings.sort" -->
								<text class="bold"> 分数结果排序：</text>
								{{ employeeData.sort }}/{{ employeeData.amount }}
							</view>
							<view class="people-info-item">
								<text class="bold"> 近七日井下违章作业次数：</text>
								{{ employeeData.violationNumber }}
							</view>
							<view class="people-info-item">
								<text class="bold"> 近七次入井安全设备穿戴违规次数： </text>
								<text>穿戴设备不规范{{ employeeData.wrongWear }}次</text>
								<template v-if="wearDataNum">
									<text>（{{ wearDataNum.helmetNum }}次安全帽、</text>
									<text>{{ wearDataNum.shoesNum }}次胶鞋、</text>
									<text>{{ wearDataNum.rescurNum }}次自救器、</text>
									<text>{{ wearDataNum.towelNum }}次毛巾、</text>
									<text>{{ wearDataNum.capNum }}次头灯），</text>
								</template>
								<text>未穿戴设备{{ employeeData.noWear }}次</text>
							</view>

						</view>
					</u-collapse-item>
				</u-collapse>
				<view class="peopContainer">
					<u-row>
						<u-col span="4">
							<view class="warnBg" v-if="warningList.length>0">
								<view class="boldWarn">
									违章类型:
									<text>{{warningList[0].wearName}}</text>
								</view>
								<view class="boldWarn">
									违章次数:
									<text>{{warningList[0].number}}次</text>
									<text>（{{warningList[0].percentage}}%）</text>
								</view>
							</view>
							<view class="warnBg" v-if="warningList.length>0">
								<view class="boldWarn">
									违章类型:
									<text>{{warningList[1].wearName}}</text>
								</view>
								<view class="boldWarn">
									违章次数:
									<text>{{warningList[1].number}}次</text>
									<text>（{{warningList[1].percentage}}%）</text>
								</view>
							</view>
						</u-col>
						<u-col span="4">
							<view class="peopleBg" @click="toWarnDetail">
								<image src="../../static/eva/p_red.png" mode="aspectFit"
									v-if="employeeData.level == '高风险'"></image>
								<image src="../../static/eva/p_yellow.png" mode="aspectFit"
									v-if="employeeData.level == '中风险'"></image>
								<image src="../../static/eva/p_green.png" mode="aspectFit"
									v-else="employeeData.level == '低风险'"></image>
							</view>
						</u-col>
						<u-col span="4">
							<view class="warnBg" v-if="warningList.length>0">
								<view class="boldWarn">
									违章类型:
									<text>{{warningList[2].wearName}}</text>
								</view>
								<view class="boldWarn">
									违章次数:
									<text>{{warningList[2].number}}次</text>
									<text>（{{warningList[2].percentage}}%）</text>
								</view>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="search-content">
				<view class="search-item">
					<text class="search-label">部门：</text>
					<view class="selectWidth">
						<zxz-uni-data-select :multiple="true" :localdata="options.deptCodes.list" placeholder="请选择部门"
							v-model="searchParams.deptName" dataKey="key" dataValue="value" collapseTags
							@change="changeDept">
						</zxz-uni-data-select>
						<!-- <button @click="selectAll">全选</button> -->
					</view>
				</view>
				<view class="search-item">
					<text class="search-label">员工：</text>
					<view class="selectWidth">
						<zxz-uni-data-select :multiple="true" :localdata="options.username.list" placeholder="请选择员工"
							v-model="searchParams.username" dataKey="key" dataValue="value" collapseTags filterable
							@inputChange="userNameChange">
						</zxz-uni-data-select>
					</view>
				</view>
				<view class="search-item">
					<text class="search-label">时间：</text>
					<view class="selectWidth">
						<zxz-uni-data-select :localdata="options.time" placeholder="请选择时间" v-model="searchParams.time"
							dataKey="key" dataValue="value">
						</zxz-uni-data-select>
					</view>
				</view>

				<view class="btn-group">
					<u-button text="查询" type="primary" :loading="btnSearch" loadingText="查询中" class="search-btn"
						@click="toSearch"></u-button>
				</view>
			</view>
			<div class="today">{{ today }}的预测结果</div>
			<view class="risk_container">
				<u-subsection :list="list" :current="curNow" mode="subsection" :activeColor="sActiveColor"
					@change="sectionChange" class="subsect"></u-subsection>
				<u-empty v-if="riskData.length==0" mode="list" icon="../../static/listEmpty.png">
				</u-empty>
				<view class="risk_content" v-else>
					<view v-for="(item, index) in riskData" :key="index" class="risk_item"
						@click="getEmployeeData(item,curNow)">
						<view class="name-wall" :style="[borderStyle]">
							<text>{{ item.username }}</text>
						</view>
					</view>
				</view>
			</view>

		</view>
		<!-- 培训详情弹窗 -->
		<u-popup :show="showTrain&&(authDegree==2||authDegree==3)" @close="closeTrain" @open="openTrain" mode="center"
			closeable>
			<view class="popupContent">
				<view>
					<text class="bold">安全意识水平:</text>
					<text v-if="employeeData.level == '低风险'" class="green">
						放心人员
					</text>
					<text v-if="employeeData.level == '中风险'" class="yellow">
						预警人员
					</text>
					<text v-if="employeeData.level == '高风险'" class="red">
						薄弱人员
					</text>
				</view>
				<view>
					<text class="bold">违章数据统计:</text>近7日
					<text>穿戴设备违规{{ employeeData.wrongWear }}次，</text>
					<text> 违章作业次数{{ employeeData.violationNumber }}次</text>
				</view>
				<view>
					<text class="bold">学时任务:</text>
					<text v-if="portraitHours.type">
						<text>技能学习</text>
						<text v-if="portraitHours.hour!=0">{{portraitHours.hour}}学时</text>
						<!-- <text v-else>已完成</text> -->
					</text>
					<text v-else>{{portraitHours.status}}</text>
				</view>
				<view class="btn-group">
					<u-button text="进入学习" type="primary" class="search-btn" @click="toStudy"></u-button>
					<u-button text="进入测试" type="primary" class="search-btn" @click="toTest"></u-button>
				</view>
			</view>
		</u-popup>
		<!-- 违章记录详情弹窗 -->
		<u-popup :show="isWarnDetail" @close="closeWarn" @open="openWarn" mode="center" closeable>
			<view class="popupContent">
				<view class="today">井下作业违章数据 </view>
				<u--form labelPosition="left" labelWidth="70" :model="formPopup" :rules="rules" ref="uForm">
					<u-form-item label="选择时间" prop="range">
						<uni-datetime-picker v-model="formPopup.range" type="daterange" start-placeholder="开始日期"
							end-placeholder="结束日期" ref="rangePicker" /><!-- @change="getTableData(index)" -->
					</u-form-item>
					<u-form-item label="违章类型" prop="type">
						<zxz-uni-data-select :localdata="options.violationType.list" placeholder="请选择违章类型"
							v-model="formPopup.type" dataKey="key" dataValue="value" @change="changeViolationType">
						</zxz-uni-data-select>
					</u-form-item>
					<view class="btn-group">
						<u-button text="查询" type="primary" :loading="btnWarning" loadingText="查询中" class="search-btn"
							@click="toSearchWarning"></u-button>
					</view>
				</u--form>
				<u-empty v-if="violationData.length==0" mode="data" icon="../../static/dataEmpty.png">
				</u-empty>
				<u-collapse v-else>
					<view class="listScroll">
						<u-collapse-item name="violationData" class="collapse-item"
							v-for="(item,index) in violationData" :key="index" :title="item.violationDate">
							<view class="people-info-content">
								<!-- <view class="people-info-item">
									<view><text class="bold"> 违章日期： </text>{{item.violationDate}}</view>
								</view> -->
								<view class="people-info-item">
									<view><text class="bold"> 违章类型： </text>{{item.violationType}}</view>
								</view>
								<view class="people-info-item">
									<view><text class="bold"> 罚款金额： </text>{{item.penaltyAmount}}元</view>
								</view>
							</view>
						</u-collapse-item>
					</view>
				</u-collapse>

				<view class="today">入井安全设备穿戴数据 </view>
				<u-empty v-if="Object.keys(wearData).length==0" mode="data" icon="../../static/dataEmpty.png">
				</u-empty>
				<u-collapse v-else>
					<view class="listScroll">
						<u-collapse-item name="Docs guide" class="collapse-item" v-for="(item,index) in wearData"
							:key="index" :title="item.detectTime">
							<view class="people-info-content">
								<!-- <view class="people-info-item">
									<view><text class="bold"> 日期： </text>{{item.detectTime}}</view>
								</view> -->
								<view class="people-info-item">
									<view><text class="bold"> 安全帽： </text>{{item.helmetStatus}}</view>
								</view>
								<view class="people-info-item">
									<view><text class="bold"> 矿灯： </text>{{item.capLampStatus}}</view>
								</view>
								<view class="people-info-item">
									<view><text class="bold">毛巾：</text>{{item.towelStatus}}</view>
								</view>
								<view class="people-info-item">
									<view><text class="bold"> 胶鞋： </text>{{item.shoesStatus}}</view>
								</view>
								<view class="people-info-item">
									<view><text class="bold">自救器：</text>{{item.rescuerStatus}}</view>
								</view>
							</view>
						</u-collapse-item>
					</view>
				</u-collapse>
			</view>
		</u-popup>
		<!-- 安全薄弱人员信息推送弹窗 超管才推送-->
		<u-popup :show="showRoleList&&(authDegree==1)" @close="closeRoleList" @open="openRoleList" mode="center"
			closeable>
			<view class="popupContent">
				<view class="centerTitle">安全薄弱人员信息 </view>
				<u-empty v-if="RoleList.length==0" mode="data" icon="../../static/dataEmpty.png">
				</u-empty>
				<view class="search_results" v-else>
					<u-row class="result_item">
						<u-col span="4">
							<view>
								<text class="bold">姓名</text>
							</view>
						</u-col>
						<u-col span="4">
							<view>
								<text class="bold">工号</text>
							</view>
						</u-col>
						<u-col span="4">
							<view>
								<text class="bold">部门</text>
							</view>
						</u-col>
					</u-row>
					<u-row v-for="(item,index) in RoleList" :key="index" class="result_item">
						<u-col span="4">
							<view>
								<text>{{item.username}}</text>
							</view>
						</u-col>
						<u-col span="4">
							<view>
								<text>{{item.employee_id}}</text>
							</view>
						</u-col>
						<u-col span="4">
							<view>
								<text>{{item.dept_name}}</text>
							</view>
						</u-col>
					</u-row>
				</view>

			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		selectDeptName,
		portraitDetails,
		violationData,
		portraitMain,
		portraitTableData,
		portraitSort,
		portraitSelect,
		portraitSelectByTime,
		portraitWearData,
		violateData,
		wearPercent,
		violationType,
		portraitHours,
		rolePushList
	} from "../../utils/api.js"
	// import ldSelect from '@/components/ld-select/ld-select.vue'
	export default {
		// components: {
		// 	ldSelect
		// },
		data() {
			return {
				fullHeight: true,
				options: {
					deptCodes: {
						list: [],
						checked: false,
					},
					username: {
						list: [],
						checked: false,
						loading: true,
					},
					time: [{
							key: "当天",
							value: '',
						},
						{
							key: "一周",
							value: '',
						},
						{
							key: "一个月",
							value: '',
						}
					],
					violationType: {
						list: [],
						checked: false,
					},
				},
				searchParams: {
					deptName: [],
					username: '',
					time: '',
				},
				employeeData: {},
				showisDeptName: false,
				showisUsername: false,
				btnSearch: false,
				wearDataNum: {},
				list: ['安全薄弱人员', '安全预警人员'], //'安全意识较强', 
				curNow: 0,
				sActiveColor: '#d60000', //#00ba4e
				riskList: {
					low: [],
					medium: [],
					high: [],
				},
				riskData: [],
				borderColor: '#d60000', // 默认边框颜色#00ba4e
				wearData: [],
				violationData: [],
				today: "",
				// selectedAll: false, // 全选状态
				//仅用于向后端传递数据
				paramsValue: {
					name: '',
					time: '',
				},
				titleStudy: '培训要求',
				description: '点击查看详情',
				isClosable: true,
				showTrain: true,
				isWarnDetail: false,
				warningList: [],
				formPopup: {
					type: '',
					range: [],
				},
				rules: {
					type: [{
						required: true,
						message: "请选择违章类型",
						trigger: "change"
					}, ],
					range: [{
						required: true,
						message: "请选择起止日期",
						trigger: "change"
					}, ],
				},
				btnWarning: false,
				//仅用于向后端传递数据
				warningValue: {
					name: '',
					startDate: '',
					endDate: '',
					type: '',
				},
				authDegree: '',
				showRoleList: true,
				portraitHours: {},
				RoleList: [],
			}
		},
		onReachBottom() {
			if (this.fullHeight) {
				this.fullHeight = false
			}
		},
		onLoad() {
			this.userId = uni.getStorageSync('userinfo').id
			this.authDegree = uni.getStorageSync('userinfo').authDegree
			this.getOptions()
			this.getPortraitMain()
			this.getToday();
			this.updateTime()
		},
		onBackPress() {
			uni.switchTab({
				url: '/pages/evaluationReaults/evaluationReaults'
			})
			return true; // 返回true以阻止默认的返回行为
		},
		computed: {
			containHeight() {
				return {
					/*#ifdef MP-WEIXIN*/
					// 微信小程序特有代码
					height: this.fullHeight ? '100vh' : 'auto',
					/*#endif*/
					/*#ifndef MP-WEIXIN*/
					height: this.fullHeight ? 'calc(100vh - 44px)' : 'auto',
					/*#endif*/
					transition: 'all 1s ease'
				}
			},
			borderStyle() {
				return {
					border: '1px solid',
					borderColor: this.borderColor,
					// background:this.borderColor,					
					// color:'#fff'
				};
			},
		},
		methods: {
			// 获取下拉列表
			getOptions() {
				selectDeptName().then(s => {
					if (s.code === 20000) {
						// this.options.deptCodes.list = s.data
						this.options.deptCodes.list = s.data.map(item => ({
							key: item,
							value: item
						}));
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})
				violationType().then(s => {
					if (s.code === 20000) {
						this.options.violationType.list = s.data.map(item => ({
							key: item,
							value: item
						}));
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})
				portraitHours({
					userId: this.userId
				}).then(s => {
					if (s.code === 20000) {
						this.portraitHours = s.data
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})
			},
			getPortraitDetails(e, curIndex) {
				if (e) {
					portraitDetails({
						name: e.username,
						employeeId: e.employeeId,
					}).then(s => {
						if (s.code === 20000) {
							this.employeeData = {
								...this.employeeData,
								...s.data
							}
							// this.employeeData = s.data
							// console.log("s.data", s.data);
							// console.log("this.employeeData getPortraitDetails", this.employeeData);
							if (s.data != undefined && s.data.imgFile != undefined) {
								this.employeeData.imgSrc = "data:image/png;base64," + s.data.imgFile
							}
							this.getPortraitSort(e, curIndex);
						} else {
							uni.showToast({
								title: s.message,
								icon: "none"
							})
						}
					})
				} else {
					this.employeeData = {}
				}
			},
			// isDeptNameConfirm(val) {
			// 	this.showisDeptName = false
			// 	this.searchParams.deptName = val.value[0]
			// },
			// isUsernameConfirm(val) {
			// 	this.showisUsername = false
			// 	this.searchParams.username = val.value[0]
			// },
			getviolationData(e) {
				if (e) {
					violationData({
						name: e.username,
						employeeId: e.employeeId,
					}).then(s => {
						if (s.code === 20000) {
							this.employeeData = Object.assign(this.employeeData, s.data)
							this.wearDataNum = s.data.wearDataNum[0]
							// console.log("this.employeeData getviolationData", this.employeeData);
							// console.log("this.wearDataNum", this.wearDataNum);
						} else {
							uni.showToast({
								title: s.message,
								icon: "none"
							})
						}
					})
				} else {
					this.employeeData = []
					this.wearDataNum = []
				}
			},
			sectionChange(index) {
				this.curNow = index;
				if (index == 0) {
					this.sActiveColor = '#d60000'
					this.borderColor = '#d60000'
					this.riskData = this.riskList.high
				} else if (index == 1) {
					this.sActiveColor = '#fcc600'
					this.borderColor = '#fcc600'
					this.riskData = this.riskList.medium
				}
			},
			getPortraitMain() {
				portraitMain().then(s => {
					if (s.code === 20000) {
						this.riskList = s.data
						//展示登录用户的信息
						this.getEmployeeData(uni.getStorageSync('userinfo'), 0)
						// this.getWearData(uni.getStorageSync('userinfo').employeeId)
						if (s.data.medium.length > 0) {
							// //展示低风险第一个人的数据;
							// this.getEmployeeData(s.data.low[0],0);
							// this.getEmployeeData(s.data.medium[0], 0)
							this.riskData = this.riskList.high
						}
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})


			},
			getEmployeeData(e, curIndex) {
				console.log("curIndex", curIndex);
				this.employeeData = {};
				this.tableData = [];
				// for (let key in this.loadings) {
				//   this.loadings[key] = true;
				// }
				// this.rightLoading = true;
				// let params = {
				//   name: e.username,
				//   employeeId: e.employeeId,
				// };
				this.getPortraitDetails(e, curIndex);
				this.getviolationData(e);
				this.getWarningData(e.username)
				// this.getPortraitTableData(e);
			},
			// getPortraitTableData(e) {
			// 	if (e) {
			// 		portraitTableData({
			// 			name: e.username,
			// 			employeeId: e.employeeId,
			// 		}).then(s => {
			// 			if (s.code === 20000) {
			// 				if (s.data.wearData) this.wearData = s.data.wearData;
			// 				if (s.data.violationData) this.violationData = s.data.violationData;
			// 				// this.judgeLoading("tableData");
			// 			} else {
			// 				uni.showToast({
			// 					title: s.message,
			// 					icon: "none"
			// 				})
			// 			}
			// 		})
			// 	} else {
			// 		this.wearData = []
			// 		this.violationData = []
			// 	}
			// },
			getPortraitSort(e, curIndex) {
				let level = null
				if (curIndex == 0) {
					//低
					// level='低风险'
					level = '中风险'
				} else if (curIndex == 1) {
					// level='中风险'
					level = '高风险'
				}
				// else if(curIndex==2){
				// 	level='高风险'
				// }
				portraitSort({
					name: e.username,
					employeeId: e.employeeId,
					level: level
				}).then(s => {
					if (s.code === 20000) {
						this.employeeData.amount = s.data.amount
						this.employeeData.sort = s.data.sort
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})
			},
			getToday() {
				function add0(m) {
					return m < 10 ? "0" + m : m;
				}

				function format(shijianchuo) {
					var time = new Date(shijianchuo);
					var y = time.getFullYear();
					var m = time.getMonth() + 1;
					var d = time.getDate();
					return y + "-" + add0(m) + "-" + add0(d);
				}
				this.today = format(new Date());
			},
			toSearch() {
				// let params = {};
				// if (this.searchParams.username.length > 0) {
				// 	params.name = this.searchParams.username;
				// }
				// // 将参数转换为字符串
				// const paramsStr = new URLSearchParams(params).toString();
				// let that = this;					
				//当天
				if (this.searchParams.time == this.format(new Date())) {
					if (this.searchParams.username) {
						portraitSelect({
							name: this.searchParams.username.toString()
						}).then(s => {
							if (s.code === 20000) {
								this.riskList = s.data;
								// //展示低风险第一个人的数据 if (s.data.low[0])
								// this.getEmployeeData(s.data.low[0],0);
								// this.curNow = 0 //绿
								// this.sActiveColor = '#00ba4e'
								// this.borderColor = '#00ba4e'
								// this.riskData = this.riskList.low
								//
								this.getEmployeeData(s.data.high[0], 0);
								this.curNow = 0
								this.sActiveColor = '#d60000'
								this.borderColor = '#d60000'
								this.riskData = this.riskList.high
							} else {
								uni.showToast({
									title: s.message,
									icon: "none"
								})
							}
						})
					} else {
						this.getPortraitMain()
					}
				} else {
					this.paramsValue.time = this.searchParams.time
					this.paramsValue.name = this.searchParams.username.toString()
					//过滤空的参数
					const params = Object.keys(this.paramsValue).filter((key) => this.paramsValue[key] !== null && this
						.paramsValue[key] !== '' && this.paramsValue[key] !== undefined).reduce((acc, key) => ({
						...acc,
						[key]: this.paramsValue[key]
					}), {})
					portraitSelectByTime(params).then(s => {
						if (s.code === 20000) {
							this.riskList = s.data;
							//展示低风险第一个人的数据 if (s.data.low[0]) 
							// this.getEmployeeData(s.data.low[0],0);
							// this.curNow = 0 //绿
							// this.sActiveColor = '#00ba4e'
							// this.borderColor = '#00ba4e'
							// this.riskData = this.riskList.low
							this.getEmployeeData(s.data.high[0], 0);
							this.curNow = 0
							this.sActiveColor = '#d60000'
							this.borderColor = '#d60000'
							this.riskData = this.riskList.high
						} else {
							uni.showToast({
								title: s.message,
								icon: "none"
							})
						}
					})
				}
				// uni.request({
				// 	url: 'http://192.168.59.102:5389/jqmk/portrait/select',
				// 	method: 'POST',
				// 	data: paramsStr,
				// 	header: {
				// 		'Content-Type': 'application/x-www-form-urlencoded'
				// 	},
				// 	success: function(response) {
				// 		// 请求成功的回调
				// 		if (response.data.code === 20000) {
				// 			that.riskList = response.data.data;
				// 			console.log("that.riskList", that.riskList);
				// 			if (response.data.data.low.length > 0) {
				// 				//展示低风险第一个人的数据
				// 				that.getEmployeeData(response.data.data.low[0]);
				// 				that.riskData = that.riskList.low
				// 			}
				// 		} else {
				// 			uni.showToast({
				// 				title: response.data.message,
				// 				icon: "none"
				// 			});
				// 		}
				// 	},
				// 	fail: function(error) {
				// 		// 请求失败的回调
				// 		console.error(error);
				// 	}
				// });
			},
			getPortraitUpdateQuery() {
				if (this.searchParams.deptName.length > 0) {
					let that = this;
					let data = {
						includeDeptCodes: this.searchParams.deptName,
						names: this.searchParams.username
					};
					const getBaseUrl =  uni.getStorageSync('netVal');
					console.log("getBaseUrl", getBaseUrl);
					uni.request({
						url: getBaseUrl + '/jqmk/portrait/updateQuery',
						method: 'POST',
						data: data, // 直接传入对象，uni.request会自动序列化
						header: {
							'Content-Type': 'application/x-www-form-urlencoded' // 注意这里
						},
						success: function(response) {
							if (response.data.code === 20000) {
								if (response.data.data.all.length > 0) {
									that.options.username.list = response.data.data.all.map(item => ({
										key: item,
										value: item
									}));
								}
							} else {
								uni.showToast({
									title: response.data.message,
									icon: "none"
								})
							}
						},
						fail: function(error) {
							console.error(error);
						}
					});
				}
			},
			changeDept(e) {
				// console.log("e:", e);
				this.getPortraitUpdateQuery()
			},
			// selectAll() {
			// 	this.selectedAll = true;
			// 	this.options.deptCodes.list.forEach(item => {
			// 		item.selected = this.selectedAll;
			// 	});
			// },
			format(date) {
				var d = new Date(date);
				return (d.getFullYear() + "-" + ("0" + (d.getMonth() + 1)).slice(-2) + "-" + ("0" + d.getDate()).slice(-
					2));
			},
			updateTime() {
				let today = new Date();
				let lastWeek = new Date(today);
				lastWeek.setDate(today.getDate() - 7);
				let lastMonth = new Date(today);
				lastMonth.setMonth(today.getMonth() - 1);
				this.options.time = [{
						key: "当天",
						value: this.format(today)
					},
					{
						key: "一周",
						value: this.format(lastWeek)
					},
					{
						key: "一个月",
						value: this.format(lastMonth)
					}
				]
				// this.formPopup.range = this.defaultRange()
			},
			// // 默认时间范围
			// defaultRange() {
			// 	// 最近一个月
			// 	const end = new Date();
			// 	const start = new Date();
			// 	start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
			// 	const time = [this.format(start), this.format(end)];
			// 	return time;
			// },
			openTrain() {

			},
			closeTrain() {
				this.showTrain = false
			},
			toWarnDetail() {
				this.isWarnDetail = true
				console.log("toWarnDetail employeeData", this.employeeData);
				this.getWearData(this.employeeData.username)
				this.getViolateData(this.employeeData)
			},
			openWarn() {

			},
			closeWarn() {
				this.isWarnDetail = false
				//
				this.$refs.uForm.resetFields()
			},
			getWearData(e) {
				portraitWearData({
					name: e
				}).then(s => {
					if (s.code === 20000) {
						if (s.data) this.wearData = s.data
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})
			},
			getViolateData(e) {
				violateData({
					name: e.username
				}).then(s => {
					if (s.code === 20000) {
						if (s.data) this.violationData = s.data
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})
			},
			getWarningData(e) {
				wearPercent({
					username: e
				}).then(s => {
					if (s.code === 20000) {
						if (s.data) this.warningList = s.data.map(item => ({
							wearName: item.name || '未命名',
							number: item.number || 0,
							percentage: item.percentage || 0
						}))
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})
			},
			changeViolationType() {
				if (this.formPopup.type) {
					//查询操作

					// this.getSelectPeople()
				}
			},
			toSearchWarning() {
				this.warningValue.name = this.employeeData.username
				this.warningValue.startDate = this.formPopup.range[0]
				this.warningValue.endDate = this.formPopup.range[1]
				this.warningValue.type = this.formPopup.type
				//过滤空的参数
				const params = Object.keys(this.warningValue).filter((key) => this.warningValue[key] !== null && this
					.warningValue[key] !== '' && this.warningValue[key] !== undefined).reduce((acc, key) => ({
					...acc,
					[key]: this.warningValue[key]
				}), {})
				violateData(params).then(s => {
					if (s.code === 20000) {
						if (s.data) this.violationData = s.data
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})
			},
			toStudy() {
				uni.navigateTo({
					url: '/pages/intensiveTraining/dataManagement'
				})
			},
			toTest() {
				uni.navigateTo({
					url: '/pages/onlineTesting/multipleChoice'
				})
			},
			closeRoleList() {
				this.showRoleList = false
			},
			openRoleList() {
				this.titleStudy = '信息提醒'
				// 对接口 
				rolePushList().then(s => {
					if (s.code === 20000) {
						this.RoleList = s.data
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})
			},
			openAlert() {
				if (this.authDegree == 1) {
					this.showRoleList = true
				} else {
					this.showTrain = true
				}
			},
			userNameChange(e) {
				// console.log("3", e);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		// background: url("../../static/bg.png");
		// background-size: cover;
		// background:linear-gradient(#F7FDF9 5%,#BFE8FA 20%,#CDEEFF 100%);
		background: linear-gradient(#BDD7FE 15%, #F6FAFF 100%);
		padding: 20rpx 40rpx;
		width: 100%;
		position: relative;
		box-sizing: border-box;
	}

	.search-content {
		box-sizing: border-box;
		padding: 20rpx 15rpx;
		width: 100%;
		position: relative;
		background: #ffffff;

		.search-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 100%;
			position: relative;
			margin-top: 10rpx;
			font-size: 30rpx;
			box-sizing: border-box;
			padding: 10rpx 20rpx;

			.select-border {
				width: 80%;
				height: 38px;
				line-height: 38px;
				border: 1px solid #dadbde;
				border-radius: 50rpx;
				color: #B1B1B1;
				box-sizing: border-box;
				padding: 0rpx 25rpx;
				font-size: 16px;
				// z-index: 0;

				.selectedTxt {
					color: rgb(48, 49, 51);
				}
			}

			.select-border-has {
				width: 80%;
				height: 38px;
				line-height: 38px;
				border: 1px solid #dadbde;
				border-radius: 50rpx;
				// color: #B1B1B1;
				box-sizing: border-box;
				padding: 0rpx 25rpx;
				font-size: 16px;
				// z-index: 9;
				position: relative;
				display: flex;
				align-items: center;

				.selectedTxt {
					color: rgb(48, 49, 51);
				}
			}
		}

		.search-label {
			max-width: 300rpx;
			overflow: hidden;
			// text-overflow: ellipsis;
			white-space: nowrap;
			font-size: 30rpx;
		}




	}

	.btn-group {
		display: flex;
		margin-top: 30rpx;
		width: 100%;
		position: relative;
		justify-content: space-between;

		.search-btn {
			width: 40%;
			border-radius: 100rpx;
			background: linear-gradient(to right, #7774ff, #017ffd, #01b1fd);
			color: #ffffff;
		}
	}

	.people-container {
		width: 100%;
		position: relative;

		.people-content {
			box-sizing: border-box;
			padding: 50rpx 0rpx 50rpx 0rpx;

			.collapse-item {
				background: #ffffff;
			}

			.people-info-content {
				width: 100%;

				.people-info-item {
					display: flex;
					// justify-content: space-between;
					margin-bottom: 10rpx;
					flex-wrap: wrap;
					line-height: 1.8;
				}
			}
		}
	}

	.basicInfo {
		margin-left: 20rpx;
	}

	.bold {
		font-weight: 700;
		white-space: nowrap;
	}

	.today {
		// height: 4%;
		box-sizing: border-box;
		padding: 10rpx 0px;
		text-align: left;
		line-height: 2;
		font-weight: 700;
		margin-top: 40rpx;
	}

	.risk_container {
		width: 100%;
		position: relative;
		max-height: 420rpx;
		overflow-y: auto;

		.risk_content {
			width: 100%;
			position: relative;
			overflow-wrap: break-word;
			margin-top: 20rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: flex-start;

			.risk_item {
				white-space: nowrap;
				width: calc(100% / 5);
				min-width: 130rpx;

				.name-wall {
					box-sizing: border-box;
					padding: 10rpx;
					margin: 10rpx;
					text-align: center;
				}

			}
		}
	}

	/deep/ .subsect {
		position: -webkit-sticky;
		position: sticky;
		top: 0;
		z-index: 2;
		background: #ffffff;
	}

	.inch-photo {
		width: 100%;
		height: auto;
		max-width: 78px;
		max-height: 110px;
	}

	.selectWidth {
		width: 100%;
	}

	.listScroll {
		width: 100%;
		position: relative;
		box-sizing: border-box;
		max-height: 590rpx;
		overflow-y: auto;
	}

	.green {
		color: #00ba4e;
	}

	.yellow {
		color: #fcc600;
	}

	.red {
		color: #d60000;
	}

	.popupContent {
		margin-top: 40rpx;
		position: relative;
		box-sizing: border-box;
		padding: 0rpx 40rpx 10rpx;
		width: 660rpx;
		max-height: 1300rpx;
		overflow-y: auto;
	}

	.peopContainer {
		position: relative;
		box-sizing: border-box;
		padding-top: 50rpx;
		width: 100%;
	}

	.peopleBg {
		position: relative;
		background-image: url('../../static/eva/bg.png');
		background-size: cover;
		background-position: center;
		width: 240rpx;
		height: 280rpx;

		image {
			width: 240rpx;
			height: 290rpx;

		}
	}

	.warnBg {
		position: relative;
		background-image: url('../../static/eva/border.png');
		background-size: 100% 100%;
		// background-size: contain;
		background-position: center center;
		background-repeat: no-repeat;
		box-sizing: border-box;
		padding: 30rpx 0rpx 28rpx 14rpx;
	}

	.boldWarn {
		font-weight: 500;
		// white-space: nowrap;
	}

	::-webkit-scrollbar {
		width: 5px;
		height: 5px;
	}

	::-webkit-scrollbar-thumb {
		background-color: #ccc;
	}

	.centerTitle {
		box-sizing: border-box;
		padding: 10rpx 0px;
		text-align: center;
		line-height: 2;
		font-weight: 700;
		font-size: 36rpx;
	}

	.search_results {
		border-bottom: 1px solid #F3F3F3;
		background: #f1f1f1;
		// margin-top: 30rpx;
		padding: 20rpx 20rpx;
		width: 96%;
		margin: 0 auto;
		position: relative;
		box-sizing: border-box;
		border-radius: 20rpx;

		.result_item {
			// border-radius: 20rpx;
			// box-shadow: 4px 4px 10px #888888;
			border-bottom: 1px solid #ffffff; //#D4D1D1
			padding: 20rpx;
			width: 100%;
			position: relative;
			box-sizing: border-box;
		}

		.result_item:last-child {
			border-bottom: none;
		}
	}
</style>